@extends('layouts.public')

@section('head')
    <link rel="stylesheet" href="{{cdn('js/plugins/webuploader/single.css')}}">
@endsection

@section('bodyattr')class="gray-bg"@endsection

@section('body')
    <div class="wrapper wrapper-content">
        <div class="row m-b">
            <div class="col-sm-12">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li><a href="{{route('admin.topic.topics')}}">众筹列表</a></li>
                        <li @if(!isset($user))class="active"@endif><a href="{{route('admin.topic.topics.add')}}">新增</a></li>
                        @if(isset($user))
                            <li class="active"><a href="#">编辑</a></li>
                        @endif
                    </ul>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <form action="{{route('admin.topic.topics.save')}}" method="post" class="form-horizontal ajaxForm">
                            <input type="hidden" name="id" value="{{$user->id or 0}}"/>
                           
                            <div class="form-group">
                                <label class="col-sm-2 control-label">众筹主题</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" required name="title" @if(isset($user)) value="{{$user->title or ''}}"placeholder="请填写标题" @endif autocomplete="off"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">众筹描述</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" required name="desc" @if(isset($user)) value="{{$user->desc or ''}}"placeholder="请填写标题" @endif autocomplete="off"/>
                                </div>
                            </div>
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">众筹轮播图</label>
                                <div class="col-sm-10" id="imgupload">
                                    <div id="filePicker">选择图片</div>
                                    <p style="color:#ccc;font-size:12px">为了更好地展示商品，建议上传400px*320px尺寸图片最佳</p>
                                    @if(isset($user) && $user->banners != '')
                                        @foreach(explode(',',$user['banners']) as $g)
                                        <div class="img-div">
                                            <img src="{{get_file_url($g)}}"/>
                                            <span class="cancel">×</span>
                                        </div>
                                        @endforeach
                                    @endif

                                    <input type="hidden" name="banners"  required id="banners" value="{{ $user['banners'] or '' }}"/>


                                    <input type="hidden" name="file_id" id="file_id" value="0"/>
                                </div>

                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">众筹人数</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" name="num" required  @if(isset($user)) value="{{$user->num or ''}}"placeholder="请填写众筹人数" @endif autocomplete="off"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">众筹详情</label>
                                <div class="col-sm-10">
                                    <textarea name="content" id="content" required>{{$user->content or ''}}</textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">众筹金额</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" required name="money" @if(isset($user)) value="{{$user->money or ''}}"placeholder="请填写众筹金额" @endif autocomplete="off"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">参赛规则</label>
                                <div class="col-sm-10">
                                    <textarea name="rules" id="rules" required>{{$user->rules or ''}}</textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">用户须知</label>
                                <div class="col-sm-10">
                                    <textarea name="infos" id="infos" required >{{$user->infos or ''}}</textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">分销级数</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" required name="grade" @if(isset($user)) value="{{$user->grade or ''}}"placeholder="请填写分销级数" @endif autocomplete="off"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">分销佣金比例</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" name="rates1" required @if(isset($user)) value="{{$user->rates1 or ''}}"placeholder="分销佣金比例" @endif autocomplete="off"/>
                                </div>
                                <p style="color:#ccc;font-size:12px">多级分销，请以“,”分隔，分销佣金比例是0-100</p>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">分销须知</label>
                                <div class="col-sm-10">
                                    <textarea name="shares" id="shares" required>{{$user->shares or ''}}</textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">众筹开始时间</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" name="start_date" required id="start_date" @if(isset($user)) value="{{$user->start_date or ''}}"placeholder="请填写开始时间" @endif autocomplete="off"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">众筹截止时间</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" name="end_date" required  id="end_date" @if(isset($user))  value="{{$user->end_date or ''}}"placeholder="请填写开始时间" @endif autocomplete="off"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">微信分享样式</label>
                                <div class="col-sm-3">
                                    <select name="share_id" class="form-control" required>
                                        <option value="">请选择分享样式</option>
                                        @foreach ($cates as $cate)
                                        <option value="{{$cate['id']}}"  @if ((isset($user->share_id) ? $user->share_id : '') == $cate['id']) selected="selected" @endif>{{$cate['title']}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary" type="submit">保存</button>
                                    <button class="btn btn-white" type="button" id="backBtn">返回</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('script')
    <script src="{{cdn('js/plugins/ueditor/ueditor.config.js')}}"></script>
    <script src="{{cdn('js/plugins/ueditor/ueditor.all.min.js')}}"></script>
    <script src="{{cdn('js/plugins/ueditor/lang/zh-cn/zh-cn.js')}}"></script>
    <script type="text/javascript">
        jQuery(function ($) {
            var ue = UE.getEditor('content');

            ue.ready(function () {
                ue.execCommand('serverparam', {
                    '_token': '{{csrf_token()}}',
                    'filetype': 'FT_ARTICLE_DESC',
                    'itemid': '{{$topic->id or 0}}'
                });
            });
            var ues = UE.getEditor('rules');

            ues.ready(function () {
                ues.execCommand('serverparam', {
                    '_token': '{{csrf_token()}}',
                    'filetype': 'FT_ARTICLE_DESC',
                    'itemid': '{{$topic->id or 0}}'
                });
            });
            var infos = UE.getEditor('infos');

            infos.ready(function () {
                infos.execCommand('serverparam', {
                    '_token': '{{csrf_token()}}',
                    'filetype': 'FT_ARTICLE_DESC',
                    'itemid': '{{$topic->id or 0}}'
                });
            });
            var shares = UE.getEditor('shares');

            shares.ready(function () {
                shares.execCommand('serverparam', {
                    '_token': '{{csrf_token()}}',
                    'filetype': 'FT_ARTICLE_DESC',
                    'itemid': '{{$topic->id or 0}}'
                });
            });
        });
    </script>
    <script src="{{cdn('js/plugins/webuploader/webuploader.nolog.min.js')}}"></script>
    <script src="{{cdn('js/plugins/webuploader/webuploader_public.js')}}"></script>
    <script type="text/javascript">
        jQuery(function ($) {
            singleUpload({
                _token: '{{csrf_token()}}',
                type_key: 'FT_ARTICLE_IMG',
                item_id: '{{$user->id or 0}}',
                pick: 'filePicker',
                boxid: 'imgupload',
                file_path: 'banners',
                file_id: 'file_id',
                multi: true,
                maximg: 3
            });
            $('#imgupload').find('.img-div>span').click(function () {
                sUploadDel($(this), 'banners');
            });
        });
    </script>
    <script type="text/javascript" src="{{cdn('js/plugins/laydate/laydate.js')}}"></script>
    <script type="text/javascript">
        laydate.render({
            elem: '#start_date',
            range: false,
            min: 0
        });
        laydate.render({
            elem: '#end_date',
            range: false,
            min: 0
        });
    </script>
@endsection